import { View } from "../../../mvc/core/View";
import { IToolTipItem } from "../../../../com/mui/manager/IToolTipItem";
import { GModuleEvent } from "../../mvc/GModuleEvent";
import { Cache } from "../../cache/Cache";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SEntityId } from "../../../../Message/Public/SEntityId";
import { AvatarInfo } from "../../resource/info/AvatarInfo";
import { AvatarType } from "../../resource/info/AvatarType";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { LookupPlayerData } from "./LookupPlayerData";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { BitmapTooltip } from "../common/tooltip/BitmapTooltip";
type int = number;
//class AvatarUploadPanel
    
    export  class AvatarUploadPanel extends View implements IToolTipItem
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public get mode(): string
        {
            return this._mode;
        }

        public set sex(arg1: int)
        {
            this._sex = arg1;
            return;
        }

        public set mode(arg1: string)
        {
            this._mode = arg1;
            if (this._mode != GModuleEvent.Mode_Self) 
            {
                if (this.hasEventListener(flash.events.MouseEvent.CLICK)) 
                {
                    removeEventListener(flash.events.MouseEvent.CLICK, this.onAvatarClickHandler);
                }
            }
            else 
            {
                this.updateUploadAvatar(Cache.instance.login.loginGame.player.photo);
                this.toolTipData = Language.getString(30267);
                addEventListener(flash.events.MouseEvent.CLICK, this.onAvatarClickHandler);
            }
            return;
        }

        /* internal  */onAvatarClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.Role_AvatarUploadOpen));
            return;
        }

        public updateUploadAvatar(arg1: int, arg2: SEntityId=null): void
        {
            this._avatarImg.bitmapData = null;
            if (this._mode != GModuleEvent.Mode_Self) 
            {
                this.updateOtherUploadAvatar(arg1, arg2);
            }
            else if (Cache.instance.login.loginGame.player.photo) 
            {
                AvatarInfo.getUpdateAvatar(Cache.instance.role.entityInfo.entityId, AvatarType.UPLOADSMALL, this.loadUpdateAvatarEnd);
            }
            else 
            {
                LoaderHelp.addResCallBack(ResFileConst.AvatarUpload, this.onResLoaded);
            }
            return;
        }

        /* internal  */updateOtherUploadAvatar(arg1: int, arg2: SEntityId=null): void
        {
            this.toolTipData = null;
            if (this._mode == GModuleEvent.Mode_ArenaCross || this._mode == GModuleEvent.Mode_Other && !arg1 || this._mode == GModuleEvent.Mode_Wrestle) 
            {
                LoaderHelp.addResCallBack(ResFileConst.AvatarUpload, this.onResLoaded);
            }
            else if (this._mode == GModuleEvent.Mode_Other) 
            {
                if (arg2 == null) 
                {
                    arg2 = LookupPlayerData.lookupData.miniPlayer.entityId;
                }
                AvatarInfo.getUpdateAvatar(arg2, AvatarType.UPLOADSMALL, this.loadUpdateAvatarEnd);
                AvatarInfo.getUpdateAvatar(arg2, AvatarType.UPLOADBIG, this.loadBigAvatarEnd);
            }
            return;
        }

        /* internal  */loadUpdateAvatarEnd(arg1: ImageInfo): void
        {
            this._avatarImg.bitmapData = arg1.bitmapData;
            this._avatarImg.width = 38;
            this._avatarImg.height = 38;
            return;
        }

        /* internal  */loadBigAvatarEnd(arg1: ImageInfo): void
        {
            this.toolTipData = arg1.bitmapData;
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 44, 44, this, ImagesConst.PackItemBg);
            ToolTipsManager.register(this);
            this._avatarImg = new Object /* flash.display.Bitmap */();
            this._avatarImg.x = 3;
            this._avatarImg.y = 3;
            addChild(this._avatarImg);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            var loc1=0;
            if (this._mode != GModuleEvent.Mode_Self) 
            {
                if (this._mode != GModuleEvent.Mode_Other) 
                {
                    if (this._mode == GModuleEvent.Mode_ArenaCross && LookupPlayerData.arenaCrossLookInfo && LookupPlayerData.arenaCrossLookInfo.miniPlayer) 
                    {
                        loc1 = LookupPlayerData.arenaCrossLookInfo.miniPlayer.sex;
                    }
                    else if (this._mode == GModuleEvent.Mode_Wrestle && LookupPlayerData.wrestleLookInfo && LookupPlayerData.wrestleLookInfo.miniPlayer) 
                    {
                        loc1 = LookupPlayerData.wrestleLookInfo.miniPlayer.sex;
                    }
                }
                else if (this._sex == -1) 
                {
                    if (LookupPlayerData.lookupData && LookupPlayerData.lookupData.miniPlayer) 
                    {
                        loc1 = LookupPlayerData.lookupData.miniPlayer.sex;
                    }
                }
                else 
                {
                    loc1 = this._sex;
                }
            }
            else 
            {
                loc1 = Cache.instance.role.entityInfo.sex;
            }
            this._avatarImg.bitmapData = GlobalClass.getBitmapData("AvatarSmall_" + loc1);
            this._avatarImg.width = 38;
            this._avatarImg.height = 38;
            this._sex = -1;
            if (this._mode != GModuleEvent.Mode_Self) 
            {
                this.toolTipData = GlobalClass.getBitmapData("AvatarMax_" + loc1);
            }
            return;
        }

        public reset(): void
        {
            this._avatarImg.bitmapData = null;
            return;
        }

        public clean(): void
        {
            this._avatarImg.bitmapData = null;
            return;
        }

        public get toolTipData()
        {
            return this._toolTipData;
        }

        public set toolTipData(arg1)
        {
            if (arg1 == null || arg1 == "") 
            {
                ToolTipsManager.unregister(this);
            }
            else if (typeof arg1 === "string") 
            {
                ToolTipsManager.register(this);
            }
            else if (arg1 is flash.display.BitmapData) 
            {
                ToolTipsManager.register(this, BitmapTooltip);
            }
            this._toolTipData = arg1;
            return;
        }

        /* internal */ /* var */_avatarImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sex: int=-1;

        /* internal */ /* var */_mode: string="自己";

        /* internal */ /* var */_toolTipData;
    }
